/*
 * 版权所有 (c) 2022-2099 TBIT。保留所有权利。
 */

package com.tbit.main.sms.client.impl;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.tbit.common.utils.TbitHttpServiceUtil;
import com.tbit.main.sms.client.dto.SmsSendReqDTO;
import com.tbit.main.sms.enums.template.UQSmsTemplateEnum;
import com.tbit.main.sms.properties.SmsChannelProperties;

/**
 * @author <a href="mailto:li.yao@tbit.com.cn">yao</a>
 * @version 4.1.0
 * @since 2024/7/12 10:02
 */
public class UQSmsClient extends AbstractSmsClient {


    public UQSmsClient(SmsChannelProperties properties) {
        super(properties);
        Assert.notEmpty(properties.getApiKey(), "apiKey 不能为空");
        Assert.notEmpty(properties.getApiSecret(), "apiSecret 不能为空");
        Assert.notEmpty(properties.getSignature(), "signature 不能为空");
        Assert.notEmpty(properties.getApiTemplateCode(), "apiTemplateCode 不能为空");
    }

    @Override
    protected void doInit() {

    }

    @Override
    protected void doSend(SmsSendReqDTO dto) {

        UQSmsTemplateEnum template = UQSmsTemplateEnum.getTemplate(properties.getApiTemplateCode());
        String params = StrUtil.format(template.getParams(), dto.getTemplateParams());

        TbitHttpServiceUtil.sendSms(
                properties.getApiKey(),
                properties.getSignature(),
                properties.getApiSecret(),
                dto.getMobile(),
                params,
                properties.getApiTemplateId());
    }
}
